﻿using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Seagull.FrameInspector.Seagull.DAL;

namespace Seagull.FrameInspector
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var openFileDialog = new OpenFileDialog();
            if(openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Read(openFileDialog.FileName);
            }
        }

        public void Read(string fileName)
        {
            listBox1.Items.Clear();
            using(var frameReader = new FrameReader(File.OpenRead(fileName)))
            {
                DateTime lastTime = DateTime.MinValue;
                foreach(var timestamp in frameReader.ReadToEnd().Take(4000))
                {
                    listBox1.Items.Add(timestamp.ToString("HHmmss.fff")
                        + (Math.Abs((timestamp - lastTime).TotalMilliseconds) > 20 ? " ******* " : ""));
                    lastTime = timestamp;
                }
            }
        }
    }

}
